home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / Apps / MOO-1.7.6.src / Thread_Manager_Extension_1.2 / Interfaces / Threads.h
Text File  |  1994-11-02  |  6KB  |  174 lines

  1. /*
  2.     File:        Threads.h
  3.  
  4.     Contains:    External Interface to Thread Manager 1.2
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. */
  10.  
  11. #ifndef __THREADS__
  12. #define __THREADS__
  13.  
  14. #include <Memory.h>
  15.  
  16. /* Thread Gestalt Selectors */
  17. enum {
  18. #define gestaltThreadMgrAttr    'thds'            /* Thread Manager attributes */
  19.     
  20.     gestaltThreadMgrPresent = 0,                /* bit true if Thread Manager is present */
  21.     gestaltSpecificMatchSupport    = 1                /* bit true if Thread Mgr supports exact match creation option */
  22. };
  23.  
  24. /* Thread states */
  25. typedef unsigned short            ThreadState;
  26. #define kReadyThreadState        ((ThreadState) 0)
  27. #define kStoppedThreadState        ((ThreadState) 1)
  28. #define kRunningThreadState        ((ThreadState) 2)
  29.  
  30. /* Thread environment characteristics */
  31. typedef void*    ThreadTaskRef;
  32.  
  33. /* Thread characteristics */
  34. typedef unsigned long            ThreadStyle;
  35. #define kCooperativeThread        (1<<0)
  36. #define kPreemptiveThread        (1<<1)
  37.  
  38. /* Thread identifiers */
  39. typedef unsigned long            ThreadID;
  40. #define kNoThreadID                ((ThreadID) 0)
  41. #define kCurrentThreadID        ((ThreadID) 1)
  42. #define kApplicationThreadID    ((ThreadID) 2)
  43.  
  44. /* Options when creating a thread */
  45. typedef unsigned long            ThreadOptions;
  46. #define kNewSuspend                (1<<0)
  47. #define kUsePremadeThread        (1<<1)
  48. #define kCreateIfNeeded            (1<<2)
  49. #define kFPUNotNeeded            (1<<3)
  50. #define kExactMatchThread        (1<<4)
  51.  
  52. /* Information supplied to the custom scheduler */
  53. struct SchedulerInfoRec {
  54.     unsigned long    InfoRecSize;
  55.     ThreadID        CurrentThreadID;
  56.     ThreadID        SuggestedThreadID;
  57.     ThreadID        InterruptedCoopThreadID;
  58. };
  59. typedef struct SchedulerInfoRec SchedulerInfoRec;
  60. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  61.  
  62. /* Prototype for thread's entry (main) routine */
  63. typedef pascal void *            (ThreadEntryProc)(void *threadParam);
  64. typedef ThreadEntryProc            *ThreadEntryProcPtr;
  65.  
  66. /* Prototype for custom thread scheduler routine */
  67. typedef pascal ThreadID            (ThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  68. typedef ThreadSchedulerProc        *ThreadSchedulerProcPtr;
  69.  
  70. /* Prototype for custom thread switcher routine */
  71. typedef pascal void                (ThreadSwitchProc)(ThreadID threadBeingSwitched, void *switchProcParam);
  72. typedef ThreadSwitchProc        *ThreadSwitchProcPtr;
  73.  
  74. /* Prototype for thread termination notification routine */
  75. typedef pascal void                (ThreadTerminationProc)(ThreadID threadTerminated, void *terminationProcParam);
  76. typedef ThreadTerminationProc    *ThreadTerminationProcPtr;
  77.  
  78. /* Prototype for debugger NewThread notification */
  79. typedef pascal void                    (DebuggerNewThreadProc)(ThreadID threadCreated);
  80. typedef DebuggerNewThreadProc        *DebuggerNewThreadProcPtr;
  81.  
  82. /* Prototype for debugger DisposeThread notification */
  83. typedef pascal void                    (DebuggerDisposeThreadProc)(ThreadID threadDeleted);
  84. typedef DebuggerDisposeThreadProc        *DebuggerDisposeThreadProcPtr;
  85.  
  86. /* Prototype for debugger schedule notification */
  87. typedef pascal ThreadID                (DebuggerThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  88. typedef DebuggerThreadSchedulerProc    *DebuggerThreadSchedulerProcPtr;
  89.  
  90. /* Errors */
  91. enum {
  92.     threadTooManyReqsErr    = -617,
  93.     threadNotFoundErr        = -618,
  94.     threadProtocolErr        = -619
  95. };
  96.  
  97. /* Thread Manager routines */
  98. pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  99.     = {0x303C,0x0501,0xABF2};
  100.  
  101. pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  102.     = {0x303C,0x0402,0xABF2};
  103.  
  104. pascal OSErr GetSpecificFreeThreadCount( ThreadStyle threadStyle, Size stackSize, short *freeCount )
  105.     = {0x303C,0x0615,0xABF2};
  106.  
  107. pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  108.     = {0x303C,0x0413,0xABF2};
  109.  
  110. pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  111.     = {0x303C,0x0414,0xABF2};
  112.  
  113. pascal OSErr NewThread(    ThreadStyle threadStyle,
  114.                         ThreadEntryProcPtr threadEntry,
  115.                         void *threadParam,
  116.                         Size stackSize,
  117.                         ThreadOptions options,
  118.                         void **threadResult,
  119.                         ThreadID *threadMade)
  120.     = {0x303C,0x0E03,0xABF2};
  121.  
  122. pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  123.     = {0x303C,0x0504,0xABF2};
  124.  
  125. pascal OSErr YieldToThread(ThreadID suggestedThread)
  126.     = {0x303C,0x0205,0xABF2};
  127.  
  128. pascal OSErr YieldToAnyThread(void)
  129.     = {0x42A7,0x303C,0x0205,0xABF2};
  130.  
  131. pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  132.     = {0x303C,0x0206,0xABF2};
  133.  
  134. pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  135.     = {0x303C,0x0407,0xABF2};
  136.  
  137. pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  138.     = {0x303C,0x0508,0xABF2};
  139.  
  140. pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  141.     = {0x303C,0x0512,0xABF2};
  142.  
  143. pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  144.     = {0x303C,0x0209,0xABF2};
  145.  
  146. pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  147.     = {0x303C,0x070A,0xABF2};
  148.  
  149. pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  150.     = {0x303C,0x0611,0xABF2};
  151.  
  152. pascal OSErr ThreadBeginCritical(void)
  153.     = {0x303C,0x000B,0xABF2};
  154.  
  155. pascal OSErr ThreadEndCritical(void)
  156.     = {0x303C,0x000C,0xABF2};
  157.  
  158. pascal OSErr SetDebuggerNotificationProcs (    DebuggerNewThreadProcPtr notifyNewThread,
  159.                                             DebuggerDisposeThreadProcPtr notifyDisposeThread,
  160.                                             DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  161.     = {0x303C,0x060D,0xABF2};
  162.  
  163. pascal OSErr GetThreadCurrentTaskRef (ThreadTaskRef *threadTRef)
  164.     = {0x303C,0x020E,0xABF2};
  165.  
  166. pascal OSErr GetThreadStateGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  167.     = {0x303C,0x060F,0xABF2};
  168.  
  169. pascal OSErr SetThreadReadyGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToSet)
  170.     = {0x303C,0x0410,0xABF2};
  171.  
  172.  
  173. #endif /* __THREADS__ */
  174.